/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Options.java
 *
 * Created on Oct 31, 2009, 12:53:18 PM
 */

package simulador;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

/**
 *
 * @author rangel
 */
public class Options extends javax.swing.JDialog {
	private long speed;
	private Scenario scenario;

    /** Creates new form Options */
    public Options(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
		/*
		 * Ajusta LookAndFeel
		 */
		try {
			javax.swing.UIManager.LookAndFeelInfo[] looks = javax.swing.UIManager.getInstalledLookAndFeels();
			javax.swing.UIManager.setLookAndFeel(looks[looks.length-1].getClassName());  
			javax.swing.SwingUtilities.updateComponentTreeUI(this);  
		}catch(Exception e) {  
			e.printStackTrace();  
		}
		/*
		 * Fecha dialog ao receber ESC
		 */
		javax.swing.KeyStroke stroke = javax.swing.KeyStroke.getKeyStroke("ESCAPE");
		javax.swing.Action actionListener = new AbstractAction() { 
			public void actionPerformed(ActionEvent actionEvent) {
				setVisible(false);
			} 
		} ;
		javax.swing.InputMap inputMap = rootPane.getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW);
		inputMap.put(stroke, "ESCAPE");
		rootPane.getActionMap().put("ESCAPE", actionListener);
    }
		
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    jLabel1 = new javax.swing.JLabel();
    fieldSpeed = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    fieldBotsRepulsive = new javax.swing.JTextField();
    checkBoxRadar = new javax.swing.JCheckBox();
    jLabel3 = new javax.swing.JLabel();
    fieldGoalAtraction = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    fieldLineDensity = new javax.swing.JTextField();
    buttonOk = new javax.swing.JButton();
    buttonAply = new javax.swing.JButton();
    jLabel5 = new javax.swing.JLabel();
    fieldTailSize = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Options");
    setAlwaysOnTop(true);
    setResizable(false);
    getContentPane().setLayout(new java.awt.GridBagLayout());

    jLabel1.setText("Speed:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 20;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(jLabel1, gridBagConstraints);

    fieldSpeed.setText("90");
    fieldSpeed.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        fieldSpeedActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 50;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(fieldSpeed, gridBagConstraints);

    jLabel2.setText("Repulsive Force (Bots)");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 20;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(jLabel2, gridBagConstraints);

    fieldBotsRepulsive.setText("250");
    fieldBotsRepulsive.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        fieldBotsRepulsiveActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.ipadx = 50;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(fieldBotsRepulsive, gridBagConstraints);

    checkBoxRadar.setSelected(true);
    checkBoxRadar.setText("Radar delimitation");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    getContentPane().add(checkBoxRadar, gridBagConstraints);

    jLabel3.setText("Atractive Force (Goal)");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 20;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(jLabel3, gridBagConstraints);

    fieldGoalAtraction.setText("2");
    fieldGoalAtraction.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        fieldGoalAtractionActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 50;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(fieldGoalAtraction, gridBagConstraints);

    jLabel4.setText("Line density");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 20;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(jLabel4, gridBagConstraints);

    fieldLineDensity.setText("-1");
    fieldLineDensity.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        fieldLineDensityActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.ipadx = 50;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getContentPane().add(fieldLineDensity, gridBagConstraints);

    buttonOk.setText("OK");
    buttonOk.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonOkActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 26;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
    getContentPane().add(buttonOk, gridBagConstraints);

    buttonAply.setText("Aply");
    buttonAply.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonAplyActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 26;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
    getContentPane().add(buttonAply, gridBagConstraints);

    jLabel5.setText("Tail Size");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    getContentPane().add(jLabel5, gridBagConstraints);

    fieldTailSize.setText("10");
    fieldTailSize.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        fieldTailSizeActionPerformed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    getContentPane().add(fieldTailSize, gridBagConstraints);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-382)/2, (screenSize.height-257)/2, 382, 257);
  }// </editor-fold>//GEN-END:initComponents

		private void fieldSpeedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldSpeedActionPerformed
			// TODO add your handling code here:
		}//GEN-LAST:event_fieldSpeedActionPerformed

		private void buttonAplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAplyActionPerformed
			// TODO add your handling code here:
			speed = Long.parseLong(fieldSpeed.getText());
			speed = (100 - speed)<=0? 1: (100 - speed);

			scenario.setTimeToSleep(speed);
			scenario.setRadarVisible(checkBoxRadar.isSelected());
			scenario.setKRepulsiveBots(Float.parseFloat(fieldBotsRepulsive.getText()));
			scenario.setKAtractionGoal(Float.parseFloat(fieldGoalAtraction.getText()));
			scenario.setLineDensity(Float.parseFloat(fieldLineDensity.getText()));
			scenario.setTailSize(Integer.parseInt(fieldTailSize.getText()));
			scenario.repaint();
		}//GEN-LAST:event_buttonAplyActionPerformed

		private void fieldBotsRepulsiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldBotsRepulsiveActionPerformed
			// TODO add your handling code here:
		}//GEN-LAST:event_fieldBotsRepulsiveActionPerformed

		private void fieldGoalAtractionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldGoalAtractionActionPerformed
			// TODO add your handling code here:
		}//GEN-LAST:event_fieldGoalAtractionActionPerformed

		private void fieldLineDensityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldLineDensityActionPerformed
			// TODO add your handling code here:
		}//GEN-LAST:event_fieldLineDensityActionPerformed

		private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed
			// TODO add your handling code here:
			buttonAply.doClick();
			this.setVisible(false);
		}//GEN-LAST:event_buttonOkActionPerformed

		private void fieldTailSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldTailSizeActionPerformed
			// TODO add your handling code here:
		}//GEN-LAST:event_fieldTailSizeActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Options dialog = new Options(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton buttonAply;
  private javax.swing.JButton buttonOk;
  private javax.swing.JCheckBox checkBoxRadar;
  private javax.swing.JTextField fieldBotsRepulsive;
  private javax.swing.JTextField fieldGoalAtraction;
  private javax.swing.JTextField fieldLineDensity;
  private javax.swing.JTextField fieldSpeed;
  private javax.swing.JTextField fieldTailSize;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  // End of variables declaration//GEN-END:variables

	public void setScenario(Scenario scenario) {
		this.scenario = scenario;
	}

}
